/**
 * 统一的测试数据模块
 * 集中管理所有模拟数据
 */

// 用户数据
const users = {
  'CCB': {
    id: 'ccb123',
    avatar: '/images/CCB.png',
    username: 'CCB',
    email: '22301162@bjtu.edu.cn',
    joinDate: '2025-01-01',
    nickname: 'CCB大象',
    following: 12,
    followers: 34,
    upload: '12TB',
    download: '8TB',
    ratio: '1.5',
    score: 8560,
    yangtao: 42,
    isCurrentUser: true,
    bio: '北交大学生，热爱分享，喜欢动漫和电影',
    interests: ['动漫', '电影', '编程', '音乐']
  },
  '新手小白': {
    id: 'newbie456',
    avatar: 'https://i.pravatar.cc/150?img=1',
    username: '新手小白',
    email: 'newbie@example.com',
    joinDate: '2024-03-15',
    nickname: '小白一号',
    following: 5,
    followers: 2,
    upload: '500GB',
    download: '2TB',
    ratio: '0.25',
    score: 320,
    yangtao: 3,
    isCurrentUser: false,
    bio: '刚刚加入PT站，希望大家多多指教',
    interests: ['电影', '综艺']
  },
  '影视达人': {
    id: 'movie789',
    avatar: 'https://i.pravatar.cc/150?img=2',
    username: '影视达人',
    email: 'moviefan@example.com',
    joinDate: '2023-10-20',
    nickname: '电影控',
    following: 63,
    followers: 158,
    upload: '45TB',
    download: '12TB',
    ratio: '3.75',
    score: 15690,
    yangtao: 128,
    isCurrentUser: false,
    bio: '专注分享高清影视资源，8年PT经验',
    interests: ['电影', '纪录片', '欧美剧', '日韩剧']
  },
  '站长小李': {
    id: 'admin001',
    avatar: 'https://i.pravatar.cc/150?img=3',
    username: '站长小李',
    email: 'admin@example.com',
    joinDate: '2022-01-01',
    nickname: '杨桃站长',
    following: 86,
    followers: 452,
    upload: '120TB',
    download: '20TB',
    ratio: '6.0',
    score: 56800,
    yangtao: 532,
    isCurrentUser: false,
    bio: '杨桃PT站创始人，致力于打造最好的PT资源分享社区',
    interests: ['站务管理', '服务器运维', '全部资源']
  },
  '技术宅': {
    id: 'tech123',
    avatar: 'https://i.pravatar.cc/150?img=4',
    username: '技术宅',
    email: 'tech@example.com',
    joinDate: '2023-04-12',
    nickname: '码农一号',
    following: 28,
    followers: 47,
    upload: '18TB',
    download: '15TB',
    ratio: '1.2',
    score: 8960,
    yangtao: 65,
    isCurrentUser: false,
    bio: '软件工程师，业余时间分享各类技术资源和教程',
    interests: ['编程', '技术教程', '软件工具', '开源项目']
  },
  '动漫控': {
    id: 'anime567',
    avatar: 'https://i.pravatar.cc/150?img=5',
    username: '动漫控',
    email: 'anime@example.com',
    joinDate: '2023-07-22',
    nickname: '二次元爱好者',
    following: 42,
    followers: 86,
    upload: '28TB',
    download: '6TB',
    ratio: '4.67',
    score: 12580,
    yangtao: 97,
    isCurrentUser: false,
    bio: '专注分享日本动漫资源，尤其是冷门老番',
    interests: ['动画', '漫画', '轻小说', '声优']
  }
};

// 用户ID与用户名映射表
const userIdToName = {};
Object.keys(users).forEach(username => {
  const user = users[username];
  userIdToName[user.id] = username;
});

// 关注列表数据
const followingData = {
  'ccb123': [
    { id: 'user001', nickname: '小红', avatar: '/images/CCB.png', email: 'hong@example.com' },
    { id: 'user002', nickname: '小刚', avatar: '/images/CCB.png', email: 'gang@example.com' },
    { id: 'user003', nickname: '小美', avatar: '/images/CCB.png', email: 'mei@example.com' },
    { id: 'admin001', nickname: '站长小李', avatar: 'https://i.pravatar.cc/150?img=3', email: 'admin@example.com' },
    { id: 'newbie456', nickname: '新手小白', avatar: 'https://i.pravatar.cc/150?img=1', email: 'newbie@example.com' }
  ],
  'newbie456': [
    { id: 'ccb123', nickname: 'CCB', avatar: '/images/CCB.png', email: '22301162@bjtu.edu.cn' },
    { id: 'admin001', nickname: '站长小李', avatar: 'https://i.pravatar.cc/150?img=3', email: 'admin@example.com' }
  ],
  'movie789': [
    { id: 'ccb123', nickname: 'CCB', avatar: '/images/CCB.png', email: '22301162@bjtu.edu.cn' },
    { id: 'user005', nickname: '电影爱好者', avatar: 'https://i.pravatar.cc/150?img=5', email: 'movie@example.com' },
    { id: 'user006', nickname: '影评家', avatar: 'https://i.pravatar.cc/150?img=6', email: 'critic@example.com' }
  ]
};

// 粉丝列表数据
const followersData = {
  'ccb123': [
    { id: 'user010', nickname: '小李', avatar: '/images/CCB.png', email: 'li@example.com' },
    { id: 'user011', nickname: '小王', avatar: '/images/CCB.png', email: 'wang@example.com' },
    { id: 'newbie456', nickname: '新手小白', avatar: 'https://i.pravatar.cc/150?img=1', email: 'newbie@example.com' },
    { id: 'movie789', nickname: '影视达人', avatar: 'https://i.pravatar.cc/150?img=2', email: 'moviefan@example.com' }
  ],
  'admin001': [
    { id: 'ccb123', nickname: 'CCB', avatar: '/images/CCB.png', email: '22301162@bjtu.edu.cn' },
    { id: 'newbie456', nickname: '新手小白', avatar: 'https://i.pravatar.cc/150?img=1', email: 'newbie@example.com' },
    { id: 'movie789', nickname: '影视达人', avatar: 'https://i.pravatar.cc/150?img=2', email: 'moviefan@example.com' },
    { id: 'user020', nickname: '技术宅', avatar: 'https://i.pravatar.cc/150?img=7', email: 'tech@example.com' },
    { id: 'user021', nickname: '日剧迷', avatar: 'https://i.pravatar.cc/150?img=8', email: 'japan@example.com' }
  ]
};

// 用户记录数据
const userRecords = {
  'ccb123': [
    { id: 1, type: '上传', detail: '上传了种子《电影A》', time: '2024-06-01 12:00', score: '+100', yangtao: '+2' },
    { id: 2, type: '下载', detail: '下载了种子《软件B》', time: '2024-06-02 09:30', score: '-50', yangtao: '0' },
    { id: 3, type: '上传', detail: '上传了种子《动漫C》', time: '2024-06-03 15:20', score: '+80', yangtao: '+1' },
    { id: 4, type: '下载', detail: '下载了种子《电影D》', time: '2024-06-04 18:10', score: '-30', yangtao: '-1' },
    { id: 5, type: '上传', detail: '上传了种子《纪录片E》', time: '2024-06-05 10:45', score: '+120', yangtao: '+3' }
  ],
  'newbie456': [
    { id: 1, type: '下载', detail: '下载了种子《电影A》', time: '2024-06-02 14:20', score: '-20', yangtao: '0' },
    { id: 2, type: '下载', detail: '下载了种子《动漫B》', time: '2024-06-03 18:30', score: '-30', yangtao: '-1' }
  ],
  'movie789': [
    { id: 1, type: '上传', detail: '上传了种子《好莱坞电影合集》', time: '2024-05-15 09:20', score: '+200', yangtao: '+5' },
    { id: 2, type: '上传', detail: '上传了种子《独立电影精选》', time: '2024-05-20 11:30', score: '+150', yangtao: '+3' },
    { id: 3, type: '上传', detail: '上传了种子《电影解说合集》', time: '2024-05-25 14:40', score: '+120', yangtao: '+2' },
    { id: 4, type: '下载', detail: '下载了种子《电影制作教程》', time: '2024-05-28 16:50', score: '-40', yangtao: '0' }
  ]
};

// 种子列表数据
const seeds = [
  {
    id: 'seed001', 
    title: '电影A - 高清蓝光版', 
    category: '电影',
    size: '45.6GB', 
    uploadTime: '2024-06-01', 
    uploader: 'ccb123',
    downloads: 128,
    seeders: 15,
    leechers: 5
  },
  {
    id: 'seed002', 
    title: '软件开发教程合集', 
    category: '教程',
    size: '12.2GB', 
    uploadTime: '2024-06-02', 
    uploader: 'tech123',
    downloads: 56,
    seeders: 8,
    leechers: 2
  },
  {
    id: 'seed003', 
    title: '动漫合集2024', 
    category: '动漫',
    size: '76.8GB', 
    uploadTime: '2024-06-03', 
    uploader: 'anime567',
    downloads: 210,
    seeders: 25,
    leechers: 12
  }
];

// 消息数据
const messages = {
  'ccb123': [
    { id: 'msg001', sender: 'admin001', receiver: 'ccb123', content: '欢迎加入我们的社区！', time: '2024-05-20 10:15', read: true },
    { id: 'msg002', sender: 'newbie456', receiver: 'ccb123', content: '你上传的资源非常好，谢谢分享！', time: '2024-05-25 15:30', read: false },
    { id: 'msg003', sender: 'movie789', receiver: 'ccb123', content: '能否帮我找一下这部电影？', time: '2024-06-01 09:45', read: false }
  ]
};

/**
 * 获取统一的测试数据
 * @param {string} type - 数据类型: user, following, followers, records, seeds, messages
 * @param {string} key - 查询关键字 (用户名、ID等)
 * @returns {object} 对应的测试数据
 */
export const getMockData = (type, key) => {
  console.log(`获取模拟数据: 类型=${type}, 关键字=${key}`);
  
  switch (type) {
    case 'user':
      // 支持通过用户名和ID查询
      if (users[key]) {
        return { data: users[key] };
      } else if (userIdToName[key]) {
        return { data: users[userIdToName[key]] };
      }
      return { data: users['CCB'] }; // 默认返回CCB
      
    case 'following':
      return { data: followingData[key] || [] };
      
    case 'followers':
      return { data: followersData[key] || [] };
      
    case 'records':
      return { data: userRecords[key] || [] };
      
    case 'seeds':
      if (key) {
        // 根据上传者ID筛选种子
        return { data: seeds.filter(seed => seed.uploader === key) };
      }
      return { data: seeds };
      
    case 'messages':
      return { data: messages[key] || [] };
      
    case 'all':
      // 返回所有数据，用于调试
      return {
        users,
        followingData,
        followersData,
        userRecords,
        seeds,
        messages
      };
      
    default:
      console.error('未知的数据类型:', type);
      return { data: null };
  }
}; 